﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import org.aswing.event.*;

    public class DefaultListSelectionModel extends EventDispatcher implements ListSelectionModel {

        public static const SINGLE_SELECTION:int = 0;
        public static const MULTIPLE_SELECTION:int = 1;

        private static var MIN:int = -1;
        private static var MAX:int = 2147483647;

        private var value:Array;
        private var minIndex:int;
        private var maxIndex:int;
        private var anchorIndex:int;
        private var leadIndex:int;
        private var selectionMode:int;

        public function DefaultListSelectionModel(){
            this.value = [];
            this.minIndex = MAX;
            this.maxIndex = MIN;
            this.anchorIndex = -1;
            this.leadIndex = -1;
            this.selectionMode = MULTIPLE_SELECTION;
        }
        public function setSelectionInterval(_arg1:int, _arg2:int, _arg3:Boolean=true):void{
            var _local4:int;
            if ((((_arg1 < 0)) || ((_arg2 < 0)))){
                this.clearSelection(_arg3);
                return;
            };
            if (this.getSelectionMode() == SINGLE_SELECTION){
                _arg1 = _arg2;
            };
            this.updateLeadAnchorIndices(_arg1, _arg2);
            var _local5:int = Math.min(_arg1, _arg2);
            var _local6:int = Math.max(_arg1, _arg2);
            var _local7:Boolean;
            if ((((_local5 == this.minIndex)) && ((_local6 == this.maxIndex)))){
                _local4 = _local5;
                while (_local4 <= _local6) {
                    if (this.value[_local4] != true){
                        _local7 = true;
                        break;
                    };
                    _local4++;
                };
            } else {
                _local7 = true;
            };
            if (_local7){
                this.minIndex = _local5;
                this.maxIndex = _local6;
                this.clearSelectionImp();
                _local4 = this.minIndex;
                while (_local4 <= this.maxIndex) {
                    this.value[_local4] = true;
                    _local4++;
                };
                this.fireListSelectionEvent(_local5, _local6, _arg3);
            };
        }
        public function addSelectionInterval(_arg1:int, _arg2:int, _arg3:Boolean=true):void{
            if ((((_arg1 < 0)) || ((_arg2 < 0)))){
                return;
            };
            if (this.getSelectionMode() == SINGLE_SELECTION){
                this.setSelectionInterval(_arg1, _arg2);
                return;
            };
            this.updateLeadAnchorIndices(_arg1, _arg2);
            var _local4:int = Math.min(_arg1, _arg2);
            var _local5:int = Math.max(_arg1, _arg2);
            var _local6:Boolean;
            var _local7:int = _local4;
            while (_local7 <= _local5) {
                if (this.value[_local7] != true){
                    this.value[_local7] = true;
                    _local6 = true;
                };
                _local7++;
            };
            this.minIndex = Math.min(_local4, this.minIndex);
            this.maxIndex = Math.max(_local5, this.maxIndex);
            if (_local6){
                this.fireListSelectionEvent(_local4, _local5, _arg3);
            };
        }
        public function removeSelectionInterval(_arg1:int, _arg2:int, _arg3:Boolean=true):void{
            if ((((_arg1 < 0)) || ((_arg2 < 0)))){
                return;
            };
            var _local4:int = Math.min(_arg1, _arg2);
            var _local5:int = Math.max(_arg1, _arg2);
            _local4 = Math.max(_local4, this.minIndex);
            _local5 = Math.min(_local5, this.maxIndex);
            if (_local4 > _local5){
                return;
            };
            this.updateLeadAnchorIndices(_arg1, _arg2);
            if ((((_local4 == this.minIndex)) && ((_local5 == this.maxIndex)))){
                this.clearSelection();
                return;
            };
            if ((((_local4 > this.minIndex)) && ((_local5 < this.maxIndex)))){
            } else {
                if ((((_local4 > this.minIndex)) && ((_local5 == this.maxIndex)))){
                    this.maxIndex = (_local4 - 1);
                } else {
                    this.minIndex = (_local5 + 1);
                };
            };
            var _local6:int = _local4;
            while (_local6 <= _local5) {
                this.value[_local6] = undefined;
                _local6++;
            };
            this.fireListSelectionEvent(_local4, _local5, _arg3);
        }
        public function getMinSelectionIndex():int{
            if (this.isSelectionEmpty()){
                return (-1);
            };
            return (this.minIndex);
        }
        public function getMaxSelectionIndex():int{
            return (this.maxIndex);
        }
        public function isSelectedIndex(_arg1:int):Boolean{
            return ((this.value[_arg1] == true));
        }
        private function updateLeadAnchorIndices(_arg1:int, _arg2:int):void{
            this.anchorIndex = _arg1;
            this.leadIndex = _arg2;
        }
        public function getAnchorSelectionIndex():int{
            return (this.anchorIndex);
        }
        public function setAnchorSelectionIndex(_arg1:int):void{
            this.anchorIndex = _arg1;
        }
        public function getLeadSelectionIndex():int{
            return (this.leadIndex);
        }
        public function setLeadSelectionIndex(_arg1:int):void{
            this.leadIndex = _arg1;
        }
        public function clearSelection(_arg1:Boolean=true):void{
            var _local2:int;
            if (!this.isSelectionEmpty()){
                _local2 = this.maxIndex;
                this.minIndex = MAX;
                this.maxIndex = MIN;
                this.clearSelectionImp();
                this.fireListSelectionEvent(0, _local2, _arg1);
            };
        }
        private function clearSelectionImp():void{
            this.value = [];
        }
        public function isSelectionEmpty():Boolean{
            return ((this.minIndex > this.maxIndex));
        }
        public function insertIndexInterval(_arg1:int, _arg2:int, _arg3:Boolean, _arg4:Boolean=true):void{
            var _local10:Array;
            var _local5:int = (_arg3) ? _arg1 : (_arg1 + 1);
            var _local6:int = ((_local5 + _arg2) - 1);
            var _local7:Boolean;
            if (this.isSelectionEmpty()){
            } else {
                if (this.minIndex >= _local5){
                    this.minIndex = (this.minIndex + _arg2);
                    this.maxIndex = (this.maxIndex + _arg2);
                    _local7 = true;
                } else {
                    if (this.maxIndex < _local5){
                    } else {
                        if ((((_local5 > this.minIndex)) && ((_local5 <= this.maxIndex)))){
                            this.maxIndex = (this.maxIndex + _arg2);
                            _local7 = true;
                        };
                    };
                };
            };
            if (_local7){
                if (_local5 == 0){
                    this.value = new Array(_arg2).concat(this.value);
                } else {
                    _local10 = this.value.splice(_local5);
                    this.value = this.value.concat(new Array(_arg2)).concat(_local10);
                };
            };
            var _local8:int = this.leadIndex;
            if ((((_local8 > _arg1)) || (((_arg3) && ((_local8 == _arg1)))))){
                _local8 = (this.leadIndex + _arg2);
            };
            var _local9:int = this.anchorIndex;
            if ((((_local9 > _arg1)) || (((_arg3) && ((_local9 == _arg1)))))){
                _local9 = (this.anchorIndex + _arg2);
            };
            if (((!((_local8 == this.leadIndex))) || (!((_local9 == this.anchorIndex))))){
                this.updateLeadAnchorIndices(_local9, _local8);
            };
            if (_local7){
                this.fireListSelectionEvent(_local5, (_local6 + _arg2), _arg4);
            };
        }
        public function removeIndexInterval(_arg1:int, _arg2:int, _arg3:Boolean=true):void{
            var _local8:int;
            var _local4:int = Math.min(_arg1, _arg2);
            var _local5:int = Math.max(_arg1, _arg2);
            var _local6:int = ((_local5 - _local4) + 1);
            var _local7:Boolean;
            if (this.isSelectionEmpty()){
                _local7 = false;
            } else {
                if ((((this.minIndex >= _local4)) && ((this.maxIndex <= _local5)))){
                    this.minIndex = MAX;
                    this.maxIndex = MIN;
                    this.clearSelectionImp();
                } else {
                    if (this.maxIndex < _local4){
                        this.value.splice(_local4, _local6);
                    } else {
                        if (this.minIndex > _local5){
                            this.value.splice(_local4, _local6);
                            this.minIndex = (this.minIndex - _local6);
                            this.maxIndex = (this.maxIndex - _local6);
                        } else {
                            if ((((((this.minIndex < _local4)) && ((this.maxIndex >= _local4)))) && ((this.maxIndex <= _local5)))){
                                this.value.splice(_local4, _local6);
                                _local8 = (_local4 - 1);
                                while (_local8 >= this.minIndex) {
                                    this.maxIndex = _local8;
                                    if (this.value[_local8] == true){
                                        break;
                                    };
                                    _local8--;
                                };
                            } else {
                                if ((((this.minIndex >= _local4)) && ((this.maxIndex > _local5)))){
                                    this.value.splice(_local4, _local6);
                                    this.maxIndex = (this.maxIndex - _local6);
                                    _local8 = (_local4 - 1);
                                    while (_local8 <= this.maxIndex) {
                                        this.minIndex = _local8;
                                        if (this.value[_local8] == true){
                                            break;
                                        };
                                        _local8++;
                                    };
                                } else {
                                    if ((((this.minIndex < _local4)) && ((this.maxIndex > _local5)))){
                                        this.value.splice(_local4, _local6);
                                        this.maxIndex = (this.maxIndex - _local6);
                                    } else {
                                        _local7 = false;
                                    };
                                };
                            };
                        };
                    };
                };
            };
            var _local9:int = this.leadIndex;
            if ((((_local9 == 0)) && ((_local4 == 0)))){
            } else {
                if (_local9 > _local5){
                    _local9 = (this.leadIndex - _local6);
                } else {
                    if (_local9 >= _local4){
                        _local9 = (_local4 - 1);
                    };
                };
            };
            var _local10:int = this.anchorIndex;
            if ((((_local10 == 0)) && ((_local4 == 0)))){
            } else {
                if (_local10 > _local5){
                    _local10 = (this.anchorIndex - _local6);
                } else {
                    if (_local10 >= _local4){
                        _local10 = (_local4 - 1);
                    };
                };
            };
            if (((!((_local9 == this.leadIndex))) || (!((_local10 == this.anchorIndex))))){
                this.updateLeadAnchorIndices(_local10, _local9);
            };
            if (_local7){
                this.fireListSelectionEvent(_local4, (_local5 + _local6), _arg3);
            };
        }
        public function setSelectionMode(_arg1:int):void{
            this.selectionMode = _arg1;
        }
        public function getSelectionMode():int{
            return (this.selectionMode);
        }
        public function addListSelectionListener(_arg1:Function):void{
            addEventListener(SelectionEvent.LIST_SELECTION_CHANGED, _arg1);
        }
        public function removeListSelectionListener(_arg1:Function):void{
            removeEventListener(SelectionEvent.LIST_SELECTION_CHANGED, _arg1);
        }
        protected function fireListSelectionEvent(_arg1:int, _arg2:int, _arg3:Boolean):void{
            dispatchEvent(new SelectionEvent(SelectionEvent.LIST_SELECTION_CHANGED, _arg1, _arg2, _arg3));
        }
        override public function toString():String{
            return ("DefaultListSelectionModel[]");
        }

    }
}//package org.aswing 
